﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;

namespace LiteFramework
{
    /// <summary>
    /// 安全令牌上下文
    /// </summary> 
    [Serializable()]
    [ComVisible(true)]
    [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
    public sealed class ContextToken : MarshalByRefObject, ILogicalThreadAffinative
    {
        // 成员...
        public readonly string SecurityToken;
        public readonly object Tag;

        public ContextToken(string securityToken)
            : this(securityToken, null)
        {
        }

        public ContextToken(string securityToken, object tag)
        {
            SecurityToken = securityToken;
            Tag = tag;
        }

        public ContextToken Copy()
        {
            return new ContextToken(this.SecurityToken, this.Tag);
        }

        public override string ToString()
        {
            if (SecurityToken == null)
                return base.ToString();
            else
                return SecurityToken;
        }
    }
}